package com.tedu.project5.controller;


import com.tedu.project5.common.Result;
import com.tedu.project5.dto.CategoryDTO;
import com.tedu.project5.dto.QueryCategorysDTO;
import com.tedu.project5.model.DdCategorysInfo;
import com.tedu.project5.service.IDdCategorysInfoService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

/**
 * <p>
 * 产品类型表 前端控制器
 * </p>
 *
 * @author mhg
 * @since 2022-06-20
 */
@Slf4j
@RestController
@RequestMapping("/project5/ddCategorysInfo")
public class DdCategorysInfoController {

    @Autowired
    private IDdCategorysInfoService iDdCategorysInfoService;

    /**
     * 查询分类列表
     * @return
     * http://localhost:9999/project5/ddCategorysInfo/listAll
     */
    @CrossOrigin
    @PostMapping("/listAll")
    public Result list(@RequestBody QueryCategorysDTO dto){
        log.info("参数值--:"+ dto);
        return iDdCategorysInfoService.queryExample(dto);
    }

    /**
     * 新增分类
     * @param category
     * @return
     */
    @CrossOrigin
    @PostMapping("/addCategory")
    public Result addUser(@RequestBody DdCategorysInfo category){
        log.info("参数值--："+ category);
        return iDdCategorysInfoService.saveCategory(category);
    }

    /**
     * 更新分类信息
     * @param dto
     * @return
     */
    @CrossOrigin
    @PostMapping("/updateById")
    public Result updateById(@RequestBody CategoryDTO dto){
        log.info("参数值--："+ dto);
        return iDdCategorysInfoService.updateCategory(dto);
    }

    /**
     * 删除分类信息
     * @param id
     * @return
     */
    @CrossOrigin
    @PostMapping("/deleteById/{id}")
    public Result deleteById(@PathVariable String id){
        log.info("参数值id--："+ id);
        return iDdCategorysInfoService.deleteCategory(id);
    }
    
    
}
